require('style.less')

const Vue       = require('vue')
const VueRouter = require('vue-router')
const Vuex      = require('vuex')

Vue.use(VueRouter)
Vue.use(Vuex)

const router = new VueRouter({})

router.map({
	'/': {
		component: require('route/list'),
		name     : 'index',
	},
	'/connections': {
		component: require('route/connections'),
		name     : 'connections',
	},
	'/add': {
		component: require('route/add'),
		name     : 'add',
	},
	'/setting': {
		component: require('route/setting/index'),
		name     : 'setting',
		subRoutes: {
			'/connect': {
				component: require('route/setting/connect'),
				name     : 'setting.connect',
			},
			'/global': {
				component: require('route/setting/global'),
				name     : 'setting.global',
			},
		},
	},
	'/edit': {
		path     : '/edit',
		component: require('route/edit'),
		name     : 'edit',
	},
	'/login': {
		component: require('route/login'),
		name     : 'login',
	},
	'/register': {
		component: require('route/register'),
		name     : 'register',
	},
})

router.start({
	router,
	store: require('store.js'),
	ready () {
		const loop = () => {
			window.requestAnimationFrame(loop)
			this.$broadcast('frame', new Event('frame'))
		}

		loop()
	},
	mixins: [
		require('mixin/rpc'),
	],
	data () {
		return {
			open: false,
		}
	},
	computed: {
		title () {
			const val = this.$store.getters.title

			document.title = val

			return val
		},
	},
}, 'body')